package temp;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @Description: 坦克大战游戏入口程序（窗口）
 * @CreateTime: 2024-01-25  14:45
 * @Author: JAMILA
 * @Version: 1.0
 */

public class TankBattleGame extends JFrame {
    MyPanel mp = null;

    public static void main(String[] args) {

        TankBattleGame tankBattleGame = new TankBattleGame();

    }

    public TankBattleGame() {
        System.out.println("请输入选择：1：新游戏 2：继续上局");
        String key = new Scanner(System.in).next();
        mp = new MyPanel(key);
        Thread mpThread = new Thread(mp);
        mpThread.start();
        this.add(mp);
        //让JFrame监听画板的键盘事件
        this.addKeyListener(mp);
        //JFrame面积要大于JPanel一点点
        this.setSize(1320, 800);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);


        //在JFrame中添加响应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                Recorder.keepRecord();
                System.exit(0);
            }
        });

    }

}
